---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
      name:  <unnamed>
       log:  /Users/jesse/Dropbox/voter_id/Replication/table5.log
  log type:  text
 opened on:  17 Aug 2020, 12:12:46

. 
. use "$path/nc_dataset.dta" if new_reg == 0, clear

. 
. keep id election treat voted birth_year race_by_year age_by_year race_by_age_by_year ///
>         no_dmv_match race_string

. 
. 
. // replace voted with NA if under 18 / ineligible in that election year 
. drop if birth_year > 1998 & birth_year < 9999
(84 observations deleted)

. replace voted = . if (birth_year > 1990 & birth_year < 9999) & (election == 1 | election == 2) // 2008
(1,102,090 real changes made, 1,102,090 to missing)

. replace voted = . if (birth_year > 1992 & birth_year < 9999) & (election == 3 | election == 4) // 2010
(680,176 real changes made, 680,176 to missing)

. replace voted = . if (birth_year > 1994 & birth_year < 9999) & (election == 5 | election == 6) // 2012
(269,954 real changes made, 269,954 to missing)

. replace voted = . if (birth_year > 1996 & birth_year < 9999) & (election == 7 | election == 8) // 2014
(314 real changes made, 314 to missing)

. 
. ** create string encoding of possible pre-treatment outcome paths
. tostring voted, generate(outcome_path)
outcome_path generated as str1

. 
. by id: gen outcome_path_pretreat = outcome_path[1] + outcome_path[2] + ///
>                                                                 outcome_path[3] + outcome_path[4] + ///
>                                                                 outcome_path[5] + outcome_path[6] + ///
>                                                                 outcome_path[7] + outcome_path[8] 

. 
. gen count = 1

. 
. // keep general only
. keep if mod(election,2) == 0
(39,763,872 observations deleted)

. 
. replace voted = 0 if voted == .
(1,026,267 real changes made)

. 
. // construct age bins, give young voters who are ineligible for some election their own age bin
. gen age_bin = 11 if (birth_year > 1990 & birth_year < 9999)
(36,457,602 missing values generated)

. replace age_bin = 12 if (birth_year > 1992 & birth_year < 9999)
(2,040,528 real changes made)

. replace age_bin = 13 if (birth_year > 1994 & birth_year < 9999)
(809,862 real changes made)

. replace age_bin = 14 if (birth_year > 1996 & birth_year < 9999)
(942 real changes made)

. // give those who are eligible over the whole period their own age decile
. xtile age_decile = birth_year if (birth_year <= 1990), nq(10)

. replace age_bin = age_decile if (birth_year <= 1990)
(36,401,136 real changes made)

. drop age_decile

. 
. sort id election

. 
. gen treat_2018 = treat * (election == 12)

. 
. compress
  variable count was float now byte
  variable age_bin was float now byte
  variable treat_2018 was float now byte
  (357,874,848 bytes saved)

. 
. 
. * vanilla diff in diff
. 
. reghdfe voted treat treat_2018, a(id election) cluster(id)
(converged in 3 iterations)

HDFE Linear regression                            Number of obs   = 39,763,872
Absorbing 2 HDFE groups                           F(   2,6627311) =   10707.37
Statistics robust to heteroskedasticity           Prob > F        =     0.0000
                                                  R-squared       =     0.5856
                                                  Adj R-squared   =     0.5027
                                                  Within R-sq.    =     0.0007
Number of clusters (id)      =  6,627,312         Root MSE        =     0.3519

                             (Std. Err. adjusted for 6,627,312 clusters in id)
------------------------------------------------------------------------------
             |               Robust
       voted |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
       treat |  -.1191366   .0008174  -145.75   0.000    -.1207386   -.1175346
  treat_2018 |   .0478714   .0007596    63.02   0.000     .0463825    .0493603
------------------------------------------------------------------------------

Absorbed degrees of freedom:
---------------------------------------------------------------+
 Absorbed FE |  Num. Coefs.  =   Categories  -   Redundant     | 
-------------+-------------------------------------------------|
          id |            0         6627312        6627312 *   | 
    election |            5               6              1     | 
---------------------------------------------------------------+
* = fixed effect nested within cluster; treated as redundant for DoF computation

. local b1 = _b[treat]

. local se1 = _se[treat]

. local b1_2 = _b[treat_2018]

. local se1_2 = _se[treat_2018]

. local n1 = e(N)

. local nclust1 = e(N_clust)

. 
. * race by year
. reghdfe voted treat treat_2018, a(id race_by_year) cluster(id)
(converged in 3 iterations)

HDFE Linear regression                            Number of obs   = 39,763,872
Absorbing 2 HDFE groups                           F(   2,6627311) =   11141.79
Statistics robust to heteroskedasticity           Prob > F        =     0.0000
                                                  R-squared       =     0.5865
                                                  Adj R-squared   =     0.5038
                                                  Within R-sq.    =     0.0007
Number of clusters (id)      =  6,627,312         Root MSE        =     0.3515

                             (Std. Err. adjusted for 6,627,312 clusters in id)
------------------------------------------------------------------------------
             |               Robust
       voted |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
       treat |  -.1222922   .0008223  -148.71   0.000     -.123904   -.1206805
  treat_2018 |    .049488   .0007669    64.53   0.000     .0479848    .0509912
------------------------------------------------------------------------------

Absorbed degrees of freedom:
---------------------------------------------------------------+
 Absorbed FE |  Num. Coefs.  =   Categories  -   Redundant     | 
-------------+-------------------------------------------------|
          id |            0         6627312        6627312 *   | 
race_by_year |           29              30              1     | 
---------------------------------------------------------------+
* = fixed effect nested within cluster; treated as redundant for DoF computation

. local b2 = _b[treat]

. local se2 = _se[treat]

. local b2_2 = _b[treat_2018]

. local se2_2 = _se[treat_2018]

. local n2 = e(N)

. local nclust2 = e(N_clust)

. 
. * age by year 
. reghdfe voted treat treat_2018, a(id age_by_year) cluster(id)
(converged in 3 iterations)

HDFE Linear regression                            Number of obs   = 39,707,406
Absorbing 2 HDFE groups                           F(   2,6617900) =    8049.74
Statistics robust to heteroskedasticity           Prob > F        =     0.0000
                                                  R-squared       =     0.6025
                                                  Adj R-squared   =     0.5230
                                                  Within R-sq.    =     0.0005
Number of clusters (id)      =  6,617,901         Root MSE        =     0.3446

                             (Std. Err. adjusted for 6,617,901 clusters in id)
------------------------------------------------------------------------------
             |               Robust
       voted |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
       treat |  -.1060795   .0008392  -126.40   0.000    -.1077244   -.1044347
  treat_2018 |   .0600766   .0007833    76.69   0.000     .0585413    .0616119
------------------------------------------------------------------------------

Absorbed degrees of freedom:
---------------------------------------------------------------+
 Absorbed FE |  Num. Coefs.  =   Categories  -   Redundant     | 
-------------+-------------------------------------------------|
          id |            0         6617901        6617901 *   | 
 age_by_year |          533             534              1     | 
---------------------------------------------------------------+
* = fixed effect nested within cluster; treated as redundant for DoF computation

. local b3 = _b[treat]

. local se3 = _se[treat]

. local b3_2 = _b[treat_2018]

. local se3_2 = _se[treat_2018]

. local n3 = e(N)

. local nclust3 = e(N_clust)

. 
. * age by race by year
. reghdfe voted treat treat_2018, a(id race_by_age_by_year) cluster(id)
(dropped 24 singleton observations)
(converged in 3 iterations)

HDFE Linear regression                            Number of obs   = 39,707,382
Absorbing 2 HDFE groups                           F(   2,6617896) =    7250.56
Statistics robust to heteroskedasticity           Prob > F        =     0.0000
                                                  R-squared       =     0.6037
                                                  Adj R-squared   =     0.5244
                                                  Within R-sq.    =     0.0004
Number of clusters (id)      =  6,617,897         Root MSE        =     0.3441

                             (Std. Err. adjusted for 6,617,897 clusters in id)
------------------------------------------------------------------------------
             |               Robust
       voted |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
       treat |  -.1011849   .0008461  -119.59   0.000    -.1028432   -.0995266
  treat_2018 |    .059719   .0007911    75.49   0.000     .0581685    .0612695
------------------------------------------------------------------------------

Absorbed degrees of freedom:
----------------------------------------------------------------------+
        Absorbed FE |  Num. Coefs.  =   Categories  -   Redundant     | 
--------------------+-------------------------------------------------|
                 id |            0         6617897        6617897 *   | 
race_by_age_by_year |         2615            2616              1     | 
----------------------------------------------------------------------+
* = fixed effect nested within cluster; treated as redundant for DoF computation

. local b4 = _b[treat]

. local se4 = _se[treat]

. local b4_2 = _b[treat_2018]

. local se4_2 = _se[treat_2018]

. local n4 = e(N)

. local nclust4 = e(N_clust)

. 
. // drop 2016 general, just want difference in means in 2018 general
. drop if election == 10 
(6,627,312 observations deleted)

. 
. preserve

. 
. collapse (sum) count (mean) voted, by(outcome_path_pretreat no_dmv_match election)

. 
. *** get N by path by summing together n treated and n control
. by outcome_path: gen tot_tmp = count[6] if _n==6
(2,941 missing values generated)

. egen tot_treat = sum(tot_tmp), by(outcome_path)

. by outcome_path: replace tot_tmp = count[1] if _n == 1
(341 real changes made)

. egen tot = sum(tot_tmp), by(outcome_path)

. // N_voters is the number of voters who enter into the regression
. egen N_voters = sum(tot_tmp)

. // get number of elections
. unique election
Number of unique values of election is  5
Number of records is  3250

. // N is number of voters * number of elections
. gen long N = N_voters * r(unique)

. drop tot_tmp

. gen tot_control = tot - tot_treat

. 
. *** get weights for fw based on total n per stratum
. *** each stratum has 10 obs
. *** fw requires integers so need to round
. gen tot2 = round(tot/10)

. gen tot_treat2 = round(tot_treat/10)

. egen op = group(outcome_path)

. 
. reghdfe voted no_dmv_match [fw=tot_treat2], a(op election)
weight tot_treat2 can only contain strictly positive integers, but 870 zero values were found (will be dropped)
(converged in 3 iterations)

HDFE Linear regression                            Number of obs   =    218,730
Absorbing 2 HDFE groups                           F(   1, 218487) =     436.16
                                                  Prob > F        =     0.0000
                                                  R-squared       =     0.6348
                                                  Adj R-squared   =     0.6344
                                                  Within R-sq.    =     0.0020
                                                  Root MSE        =     0.2657

------------------------------------------------------------------------------
       voted |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
no_dmv_match |  -.0237291   .0011362   -20.88   0.000     -.025956   -.0215022
-------------+----------------------------------------------------------------
    Absorbed |    F(241, 218487) =   1574.144   0.000             (Joint test)
------------------------------------------------------------------------------

Absorbed degrees of freedom:
---------------------------------------------------------------+
 Absorbed FE |  Num. Coefs.  =   Categories  -   Redundant     | 
-------------+-------------------------------------------------|
          op |          238             238              0     | 
    election |            4               5              1     | 
---------------------------------------------------------------+

. local b5_2 = _b[no_dmv_match]

. local se5_2 = _se[no_dmv_match]

. local n5 = N

. local nclust5 = N_voters

. 
. 
. * match on pre-treatment turnout path and race
. 
. restore

. preserve

. 
. collapse (sum) count (mean) voted, by(outcome_path_pretreat no_dmv_match election race_string)

. 
. *** get N by path by summing together n treated and n control
. sort outcome_path race_string no_dmv_match

. by outcome_path race_string: gen tot_tmp = count[6] if _n==6
(11,833 missing values generated)

. egen tot_treat = sum(tot_tmp), by(outcome_path race_string)

. by outcome_path race_string: replace tot_tmp = count[1] if _n == 1
(1,549 real changes made)

. egen tot = sum(tot_tmp), by(outcome_path race_string)

. // N_voters is the number of voters who enter into the regression
. egen N_voters = sum(tot_tmp)

. // get number of elections
. unique election
Number of unique values of election is  5
Number of records is  12855

. // N is number of voters * number of elections
. gen long N = N_voters * r(unique)

. drop tot_tmp

. gen tot_control = tot - tot_treat

. 
. *** get weights for fw based on total n per stratum
. *** each stratum has 10 obs
. *** fw requires integers so need to round
. gen tot2 = round(tot/10)

. gen tot_treat2 = round(tot_treat/10)

. egen op = group(outcome_path race_string)

. 
. reghdfe voted no_dmv_match [fw=tot_treat2], a(op election)
weight tot_treat2 can only contain strictly positive integers, but 6845 zero values were found (will be dropped)
(converged in 3 iterations)

HDFE Linear regression                            Number of obs   =    218,570
Absorbing 2 HDFE groups                           F(   1, 217964) =     405.66
                                                  Prob > F        =     0.0000
                                                  R-squared       =     0.6361
                                                  Adj R-squared   =     0.6351
                                                  Within R-sq.    =     0.0019
                                                  Root MSE        =     0.2656

------------------------------------------------------------------------------
       voted |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
no_dmv_match |  -.0228855   .0011363   -20.14   0.000    -.0251126   -.0206585
-------------+----------------------------------------------------------------
    Absorbed |    F(604, 217964) =    630.028   0.000             (Joint test)
------------------------------------------------------------------------------

Absorbed degrees of freedom:
---------------------------------------------------------------+
 Absorbed FE |  Num. Coefs.  =   Categories  -   Redundant     | 
-------------+-------------------------------------------------|
          op |          601             601              0     | 
    election |            4               5              1     | 
---------------------------------------------------------------+

. local b6 = _b[no_dmv_match]

. local se6 = _se[no_dmv_match]

. local b6_2 = _b[no_dmv_match]

. local se6_2 = _se[no_dmv_match]

. local n6 = N

. local nclust6 = N_voters

. 
. restore

. 
. collapse (sum) count (mean) voted, by(outcome_path_pretreat no_dmv_match election race_string age_bin)

. 
. // drop if age is missing
. drop if age_bin == .
(1,755 observations deleted)

. 
. *** get N by path by summing together n treated and n control
. sort outcome_path race_string age_bin no_dmv_match election

. by outcome_path race_string age_bin: gen tot_tmp = count[6] if _n==6
(67,314 missing values generated)

. egen tot_treat = sum(tot_tmp), by(outcome_path race_string age_bin)

. by outcome_path race_string age_bin: replace tot_tmp = count[1] if _n == 1
(10,022 real changes made)

. egen tot = sum(tot_tmp), by(outcome_path race_string age_bin)

. // N_voters is the number of voters who enter into the regression
. egen N_voters = sum(tot_tmp)

. // get number of elections
. unique election
Number of unique values of election is  5
Number of records is  71615

. // N is number of voters * number of elections
. gen long N = N_voters * r(unique)

. drop tot_tmp

. gen tot_control = tot - tot_treat

. 
. *** get weights for fw based on total n per stratum
. *** each stratum has 10 obs
. *** fw requires integers so need to round
. gen tot2 = round(tot/10)

. gen tot_treat2 = round(tot_treat/10)

. egen op = group(outcome_path race_string age_bin)

. 
. reghdfe voted no_dmv_match [fw=tot_treat2], a(op election)
weight tot_treat2 can only contain strictly positive integers, but 53965 zero values were found (will be dropped)
(converged in 3 iterations)

HDFE Linear regression                            Number of obs   =    209,790
Absorbing 2 HDFE groups                           F(   1, 208020) =     214.22
                                                  Prob > F        =     0.0000
                                                  R-squared       =     0.6289
                                                  Adj R-squared   =     0.6257
                                                  Within R-sq.    =     0.0010
                                                  Root MSE        =     0.2679

------------------------------------------------------------------------------
       voted |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
no_dmv_match |  -.0171212   .0011698   -14.64   0.000    -.0194139   -.0148285
-------------+----------------------------------------------------------------
    Absorbed |   F(1768, 208020) =    199.254   0.000             (Joint test)
------------------------------------------------------------------------------

Absorbed degrees of freedom:
---------------------------------------------------------------+
 Absorbed FE |  Num. Coefs.  =   Categories  -   Redundant     | 
-------------+-------------------------------------------------|
          op |         1765            1765              0     | 
    election |            4               5              1     | 
---------------------------------------------------------------+

. local b7_2 = _b[no_dmv_match]

. local se7_2 = _se[no_dmv_match]

. local n7 = N 

. local nclust7 = N_voters

. 
. log close
      name:  <unnamed>
       log:  /Users/jesse/Dropbox/voter_id/Replication/table5.log
  log type:  text
 closed on:  17 Aug 2020, 12:42:31
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
